//
//  GuadeController.m
//  QRMaster
//
//  Created by myApple on 15/8/14.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "GuadeController.h"
#import "StartPageController.h"
#import "AutoLayoutFrame.h"
#import "localizControllerViewController.h"
#import "MobileRegistFirstStepController.h"
#import "InternationalControl.h"

@interface GuadeController ()<UIScrollViewDelegate>
{
    UIScrollView *scrollView;
    UIPageControl *pgct1;
    UIButton * languageBtn;
    UIButton * loginBtn;
    UIButton * resigstBtn;
    UILabel * firstBigLabel;
    UILabel * firstSmallLabel;
    UILabel * secondeBigLable;
    UILabel * secondeSmallLabel;
    UILabel * thirdBigLabel;
    UILabel * thirdSmallLabel;
    UIImageView * firstImageView;
    UIImageView * secondeImageView;
    UIImageView * thirdImageView;
}

@end

@implementation GuadeController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:YES];
    [self prepareScrollView];
    [self prepareLanguageBtn];
    [self prepareTitleView];
    [self prepareLoginView];
    // Do any additional setup after loading the view.
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
    [languageBtn setTitle:NSLocalizedString(@"loginLanguage", nil) forState:0];
    [resigstBtn setTitle:NSLocalizedString(@"registBtn", @"注册") forState:0];
    [loginBtn setTitle:NSLocalizedString(@"loginBtn", @"登录") forState:0];
    firstBigLabel.text = NSLocalizedString(@"firstBigTitle", @"酒店和公寓");
    firstSmallLabel.text = NSLocalizedString(@"firstSmallTitle", @"便捷预订，节省手续");
    secondeBigLable.text = NSLocalizedString(@"secondeBigTitle", @"办公及写字楼");
    secondeSmallLabel.text = NSLocalizedString(@"secondeSmallTitle", @"无需钥匙，便捷安全");
    thirdBigLabel.text = NSLocalizedString(@"thirdBigTitle", @"其他公共场所");
    thirdSmallLabel.text = NSLocalizedString(@"thirdSmallTitle", @"分享房卡，随时随地");
    if ([[InternationalControl userLanguage]isEqualToString:@"en"]) {
        firstSmallLabel.frame = CGRectMake(firstSmallLabel.frame.origin.x, firstSmallLabel.frame.origin.y, firstSmallLabel.frame.size.width, 55);
        NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc]initWithString:firstSmallLabel.text];
        NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]init];
        [paragraphStyle setLineSpacing:8];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [firstSmallLabel.text length])];
        firstSmallLabel.attributedText = attributedString;
        firstSmallLabel.textAlignment = NSTextAlignmentCenter;
        firstSmallLabel.numberOfLines = 2;
    }
    else
    {
         firstSmallLabel.frame = CGRectMake(firstSmallLabel.frame.origin.x, firstSmallLabel.frame.origin.y, firstSmallLabel.frame.size.width, 18);
        firstSmallLabel.numberOfLines = 1;
    }
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self animationWithCharacter];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

#pragma mark ---------语言按钮
-(void)prepareLanguageBtn
{
    languageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    languageBtn.frame = CGRectMake(UI_SCREEN_WIDTH - 90, [AutoLayoutFrame autoSizeY:60], 80, 40);
    languageBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [languageBtn setTitle:NSLocalizedString(@"loginLanguage", nil) forState:0];
    [languageBtn setTitleColor:UIColorFromRGB(0xffffff) forState:0];
    languageBtn.titleLabel.font = [UIFont systemFontOfSize:18.0];
    [languageBtn addTarget:self action:@selector(changeLanguage) forControlEvents:UIControlEventTouchUpInside];
    languageBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.view addSubview:languageBtn];
}

#pragma mark -------------- 切换语言
-(void)changeLanguage
{
    localizControllerViewController * lcv = [[localizControllerViewController alloc]init];
    [self.navigationController pushViewController:lcv animated:YES];
}

#pragma mark ------- 滚动视图
-(void)prepareScrollView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float ScreenHeight = [UIScreen mainScreen].bounds.size.height ;
    
    //进入界面滚动视图
    scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scrollView.contentSize = CGSizeMake(ScreenWidth * 3, ScreenHeight);//滚动条视图内容范围的大小
    scrollView.delegate = self;
    scrollView.canCancelContentTouches = NO;
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView.clipsToBounds = YES;
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;
    scrollView.directionalLockEnabled = NO;
    scrollView.alwaysBounceHorizontal = NO;
    scrollView.alwaysBounceVertical = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    
    //添加三张图片
    UIImage * firstImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"firstImage" ofType:@"jpg"]];
    firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    firstImageView.image = firstImage;
    [scrollView addSubview:firstImageView];
    
    UIImage * secondeImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"secondeImage" ofType:@"jpg"]];
    secondeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight)];
    secondeImageView.image = secondeImage;
    [scrollView addSubview:secondeImageView];
    
    UIImage * thirdImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"thirdImage" ofType:@"jpg"]];
    thirdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth * 2, 0, ScreenWidth, ScreenHeight)];
    thirdImageView.image = thirdImage;
    [scrollView addSubview:thirdImageView];
    
    scrollView.bounces = NO;//边缘不可拖动
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    [self.view addSubview:scrollView];
    
    //点击进入首页
   float y = [AutoLayoutFrame autoSizeY:501];
   pgct1 = [[UIPageControl alloc]initWithFrame:CGRectMake(0, y, ScreenWidth, 15)];
    
    //下方小圆圈
    pgct1.currentPageIndicatorTintColor = UIColorFromRGBAndA(0xffffff, 1.0);
    pgct1.pageIndicatorTintColor = UIColorFromRGBAndA(0xffffff, 0.5);
    pgct1.numberOfPages = 3;
    pgct1.currentPage = 0;
    [self.view addSubview:pgct1];
}

#pragma mark ----------- 字体view
-(void)prepareTitleView
{
    //第一幅图片上面的字
    float x = 0;
    float y = UI_SCREEN_HEIGHT;
    float width = UI_SCREEN_WIDTH;
    float height = 35;
    firstBigLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    firstBigLabel.font = [UIFont boldSystemFontOfSize:30.0];
    firstBigLabel.textColor = UIColorFromRGB(0xffffff);
    firstBigLabel.textAlignment = NSTextAlignmentCenter;
    firstBigLabel.text = NSLocalizedString(@"firstBigTitle", @"酒店和公寓");
    [firstImageView addSubview:firstBigLabel];
    
    height = 18;
    firstSmallLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    firstSmallLabel.font = [UIFont systemFontOfSize:18.0];
    firstSmallLabel.textAlignment = NSTextAlignmentCenter;
    firstSmallLabel.textColor = UIColorFromRGB(0xffffff);
    firstSmallLabel.text = NSLocalizedString(@"firstSmallTitle", @"便捷预订，节省手续");
    firstSmallLabel.numberOfLines = 2;
    [firstImageView addSubview:firstSmallLabel];
    
    //第二幅图片上面的字
    y = [AutoLayoutFrame autoSizeY:297];
    height = 30;
    secondeBigLable = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    secondeBigLable.font = [UIFont boldSystemFontOfSize:30.0];
    secondeBigLable.textColor = UIColorFromRGB(0xffffff);
    secondeBigLable.textAlignment = NSTextAlignmentCenter;
    secondeBigLable.text = NSLocalizedString(@"secondeBigTitle", @"办公及写字楼");
    [secondeImageView addSubview:secondeBigLable];
    
    y += height + [AutoLayoutFrame autoSizeY:24];
    height = 18;
    secondeSmallLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, height)];
    secondeSmallLabel.font = [UIFont systemFontOfSize:18.0];
    secondeSmallLabel.textAlignment = NSTextAlignmentCenter;
    secondeSmallLabel.textColor = UIColorFromRGB(0xffffff);
    secondeSmallLabel.text = NSLocalizedString(@"secondeSmallTitle", @"无需钥匙，便捷安全");
    [secondeImageView addSubview:secondeSmallLabel];
    //第三幅图片上面的字
    thirdBigLabel = [[UILabel alloc]initWithFrame:secondeBigLable.frame];
    thirdBigLabel.font = [UIFont boldSystemFontOfSize:30.0];
    thirdBigLabel.textColor = UIColorFromRGB(0xffffff);
    thirdBigLabel.textAlignment = NSTextAlignmentCenter;
    thirdBigLabel.text = NSLocalizedString(@"thirdBigTitle", @"其他公共场所");
    [thirdImageView addSubview:thirdBigLabel];
    
    thirdSmallLabel = [[UILabel alloc]initWithFrame:secondeSmallLabel.frame];
    thirdSmallLabel.font = [UIFont systemFontOfSize:18.0];
    thirdSmallLabel.textAlignment = NSTextAlignmentCenter;
    thirdSmallLabel.textColor = UIColorFromRGB(0xffffff);
    thirdSmallLabel.text = NSLocalizedString(@"thirdSmallTitle", @"分享房卡，随时随地");
    [thirdImageView addSubview:thirdSmallLabel];
}


#pragma mark -------------登录注册
-(void)prepareLoginView
{
    float x = 10;
    float y = UI_SCREEN_HEIGHT;
    float width = UI_SCREEN_WIDTH / 2.0 - x - 5;
    float height = [AutoLayoutFrame autoSizeY:48];
    
    resigstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    resigstBtn.frame = CGRectMake(x, y, width, height);
    [resigstBtn setBackgroundColor:UIColorFromRGB(0x7dc234)];
    [resigstBtn setTitleColor:UIColorFromRGB(0xffffff) forState:0];
    [resigstBtn setTitle:NSLocalizedString(@"registBtn", @"注册") forState:0];
    [resigstBtn addTarget:self action:@selector(resigstClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:resigstBtn];
    
    x += width + 5;
    loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    loginBtn.frame = CGRectMake(x, y, width, height);
    [loginBtn setBackgroundColor:[UIColor clearColor]];
    [loginBtn setTitle:NSLocalizedString(@"loginBtn", @"登录") forState:0];
    [loginBtn setTitleColor:UIColorFromRGB(0xffffff) forState:0];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:19.0];
    loginBtn.layer.borderWidth = 2.0;
    loginBtn.layer.borderColor = UIColorFromRGB(0xffffff).CGColor;
    loginBtn.layer.masksToBounds = YES;
    [loginBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
   
}

//scroollerview代理
-(void)scrollViewDidEndDecelerating:(UIScrollView *)sl
{
    int index = fabs(scrollView.contentOffset.x) / scrollView.frame.size.width;
    pgct1.currentPage = index;
}

#pragma mark --------- 注册
-(void)resigstClick
{
    MobileRegistFirstStepController * mrfsc = [[MobileRegistFirstStepController alloc]init];
    [self.navigationController pushViewController:mrfsc animated:YES];
}


#pragma mark -----------登录
-(void)loginClick
{
    StartPageController * spc = [[StartPageController alloc]init];
    [self.navigationController pushViewController:spc animated:YES];
}

#pragma mark ----------- 文字的动画
-(void)animationWithCharacter
{
    [UIView animateWithDuration:0.3 delay:0.3 options:UIViewAnimationOptionLayoutSubviews animations:^{
        CGRect bigLableRect = firstBigLabel.frame;
        CGRect smallLabelRect = firstSmallLabel.frame;
        CGRect loginRect = loginBtn.frame;
        CGRect regsitRect = resigstBtn.frame;
        bigLableRect.origin.y = [AutoLayoutFrame autoSizeY:297];
        smallLabelRect.origin.y = bigLableRect.origin.y + bigLableRect.size.height +  [AutoLayoutFrame autoSizeY:24];
        loginRect.origin.y = [AutoLayoutFrame autoSizeY:579];
        regsitRect.origin.y = loginRect.origin.y;
        firstBigLabel.frame = bigLableRect;
        firstSmallLabel.frame = smallLabelRect;
        loginBtn.frame = loginRect;
        resigstBtn.frame = regsitRect;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
